<template>
  <div class="wisdomContainer">
    <!-- 头部 -->
    <van-nav-bar
      title="正文内容"
      left-arrow
      @click-left="onClickLeft"
      class="navheadrt"
    >
      <template #right>
        <van-icon name="search" size="18" class="searchIcon" />
      </template>
    </van-nav-bar>
    <div class="bookIndexContainer">
      <div class="searchCont f">
        <input
          type="text"
          placeholder="请输入关键字"
          class="searchInput fl"
          v-model="keywords"
        />
        <div class="right f fc" @click="toSearch()">
          <van-icon name="search" class="searchicon" />
          搜索
        </div>
        <div class="right f fc" @click="drawer = true">
          <van-icon name="orders-o" class="searchicon" />
          目录
        </div>
      </div>
      <!-- 正文内容 -->
      <div class="content" v-if="isShow">
        <div class="content1" v-html="list" v-if="list != ''"></div>
        <div v-else class="nodata"><img :src="nodata" alt="" /></div>
      </div>
      <!-- 搜索内容 -->
      <div class="content" v-else>
        <p class="title f fb">
          <span>共找到{{ searchList.length }}个结果 </span
          ><span @click="isShow = true" style="color: #000">返回正文</span>
        </p>
        <ul class="searchUl">
          <li
            class="searchli"
            v-for="(item, index) in searchList"
            :key="index"
            @click="toContent(item.ID)"
          >
            {{ item.Content }}
          </li>
        </ul>
      </div>
    </div>
    <!-- 目录 -->
    <van-popup
      v-model:show="drawer"
      position="right"
      :style="{ height: '100%', width: '80%' }"
    >
      <div class="draweContent">
        <el-tree
          :data="data"
          :props="defaultProps"
          node-key="id"
          :default-expanded-keys="[1, 2]"
          @node-click="handleNodeClick"
          class="tree1"
        ></el-tree>
        <div class="fixbtn">
          <div class="confirmBtn f fc" @click="treeData">确定</div>
        </div>
      </div>
    </van-popup>
  </div>
</template>
<script>
import {
  DocumentManage,
  GetTreeData,
  getsearchContent,
  getbookContent,
} from "@/api/api";
var projectId = localStorage.getItem("projectid");
export default {
  data() {
    return {
      nodata: require("../../imgs/nodata.png"),
      tabIndex: 0,
      tabNav: [
        { id: 0, name: "浏览记录" },
        { id: 2, name: "项目管理" },
        { id: 3, name: "工艺工法" },
      ],
      list: "",
      keywords: "",
      documnetid: "",
      drawer: false,
      //树形
      data: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
      //搜索
      isShow: true,
      searchList: [],
      treeid: "",
    };
  },
  mounted() {
    this.documnetid = this.$route.query.id;
    this.DocumentManage1();
    this.GetTreeData1();
  },
  methods: {
    //返回上一层
    onClickLeft() {
      this.$router.go(-1);
    },
    //正文内容
    DocumentManage1() {
      this.$toast.loading({
        mask: true,
        message: "加载中...",
        className: "my-toast",
      });
      this.Request(
        DocumentManage({ documentid: this.documnetid, projectId: projectId })
      ).then((res) => {
        if (res.StatusCode == "200") {
          this.$toast.clear();
          this.list = res.Result;
        } else {
          this.$message({
            type: "error",
            message: res.message,
            center: "true",
          });
        }
      });
    },
    //搜索
    toSearch() {
      this.Request(
        getbookContent({
          documentid: this.documnetid,
          ProjectID: projectId,
          keywords: this.keywords,
        })
      ).then((res) => {
        if (res.StatusCode == "200") {
          this.searchList = res.Detiel;
          this.isShow = false;
        } else {
          this.$message({
            type: "error",
            message: res.message,
            center: "true",
          });
        }
      });
    },
    //搜索跳到正文
    toContent(id) {
      this.$toast.loading({
        mask: true,
        message: "加载中...",
        className: "my-toast",
      });
      this.Request(
        getsearchContent({
          Id: id,
        })
      ).then((res) => {
        if (res.StatusCode == "200") {
          this.$toast.clear();
          this.isShow = true;

          this.list = res.Result.Content;
        } else {
          this.$message({
            type: "error",
            message: res.message,
            center: "true",
          });
        }
      });
    },
    handleNodeClick(data) {
      this.treeid = data.id;

      // this.drawer = false;
    },
    treeData() {
      this.toContent(this.treeid);
      this.drawer = false;
    },
    //树形列表
    GetTreeData1() {
      this.Request(
        GetTreeData({ Id: this.documnetid, projectId: projectId })
      ).then((res) => {
        if (res.StatusCode == "200") {
          this.data = res.Detiel;
        } else {
          this.$message({
            type: "error",
            message: res.message,
            center: "true",
          });
        }
      });
    },
  },
};
</script>
<style lang="stylus" scoped>
@import '~@/assets/css/resetVant.css';

.wisdomContainer {
  width: 100%;
  height: 100%;

  .nodata {
    width: 100%;
    height: 100%;
    margin: 100px 0;
    text-align: center;

    img {
      width: 70%;
    }
  }

  .searchIcon {
    color: #fff;
  }

  .navheadrt {
    /deep/ .van-nav-bar__title, /deep/.van-icon {
      color: #fff !important;
    }
  }

  .van-nav-bar {
    width: 100%;
    height: 88px;
    // border-bottom: 1px solid #E5E5E5;
    background: #699fff;

    .van-nav-bar__title, .van-nav-bar__left, .van-nav-bar__right {
      color: #fff;
      height: 87px;
      line-height: 87px;
      font-size: $font-size-title;
      z-index: 10000;
      border: none;
    }

    .van-icon-arrow-left {
      color: #fff;
      font-size: $font-size-title;
    }

    .van-nav-bar__text {
      color: #fff;
      font-size: $font-size-title;
    }
  }

  .bookIndexContainer {
    width: 100%;
    height: calc(100% - 88px);
    padding: 30px 40px;
    box-sizing: border-box;
    overflow: hidden;

    .searchCont {
      width: 100%;
      margin-bottom: 60px;

      .searchInput {
        height: 56px;
        background: #FFFFFF;
        box-shadow: 0px 5px 16px 0px rgba(70, 70, 70, 0.26);
        border-radius: 5px;
        padding-left: 30px;
        box-sizing: border-box;
        font-size: 28px;
      }

      .right {
        width: 120px;
        height: 56px;
        margin-left: 15px;
        background: #699FFF;
        box-shadow: 0px 5px 16px 0px rgba(70, 70, 70, 0.26);
        border-radius: 5px;
        font-size: 28px;
        font-family: Microsoft YaHei;
        font-weight: 300;
        color: #FFFFFF;

        .searchicon {
          font-size: 32px;
          margin-right: 15px;
        }
      }
    }

    .content {
      width: 100%;
      height: 100%;

      .title {
        font-size: 32px;
        color: #699FFF;
        text-align: center;
        margin-bottom: 60px;
      }

      .searchUl {
        width: 100%;

        .searchli {
          width: 100%;
          font-size: 28px;
          line-height: 32px;
          border-bottom: 1px solid #ccc;
          padding-bottom: 10px;
          margin-bottom: 30px;
        }
      }
    }
  }
}

.draweContent {
  width: 100%;
  height: 100%;
  padding: 30px;
  box-sizing: border-box;
  font-size: 28px;

  .tree1 {
    font-size: 28px;

    /deep/.el-tree-node__content {
      height: 50px;
    }

    /deep/.el-tree-node__label {
      font-size: 28px;
    }
  }

  .fixbtn {
    width: 100%;
    position: fixed;
    bottom: 20px;
    left: 0;
  }

  .confirmBtn {
    width: 90%;
    height: 80px;
    border-radius: 50px;
    background: #699fff;
    color: #fff;
    margin-left: 5%;
  }
}

.content1 {
  font-size: 28px;
}
</style>